" Sections to create: Behaviour, Spacing, Apparence, Key mapping, Commands,
" Plugins, Experimental


" BEHAVIOUR "
"""""""""""""

" get out of horrible vi-compatible mode
set nocompatible

" have fifty lines of command-line (etc) history:
set history=50

" have command-line completion <Tab> (for filenames, help topics, option names)
" first list the available options and complete the longest common part, then
" have further <Tab>s cycle through the possibilities:
set wildmode=list:longest,full

"Don't tab complete files with these extenstions
set wildignore=*.class,*.swp,*.o,*.pyc

" Shows autocomplete menu for commands
set wildmenu

if has('autocmd')
   " first clear any existing autocommands:
   autocmd!

   " * User Interface

   " This autocommand jumps to the last known position in a file
   " just after opening it, if the '" mark is set: >
   :au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif
endif

" Keep cursor in same column when jumping from file to file
set nostartofline 

" Set a pdf printer as default printer
set printdevice=pdfprinter

" Splitting a window will put the new window right of the current one
set splitright

" Minimal number of screen lines to keep above and below the cursor.
set scrolloff=4

" have the mouse enabled all
if has('mouse')
   set mouse=a
endif

"** Search & Replace

" make searches case-insensitive, unless they contain upper-case letters:
set ignorecase
set smartcase

" show the `best match so far' as search strings are typed:
set incsearch

" assume the /g flag on :s substitutions to replace all matches in a line:
"set gdefault

" don't have files trying to override this .vimrc:
set nomodeline


" TEXT FORMATTING "
"""""""""""""""""""

"** General


" don't make it look like there are line breaks where there aren't:
set nowrap

" make backspace work normal (non-vi style)
set backspace=indent,eol,start 

" use indents of 2 spaces, and have them copied down lines:
set shiftwidth=3
set shiftround
set tabstop=3
set expandtab
set autoindent

" normally don't automatically format `text' as it is typed, IE only do this
" with comments, at 79 characters:
set formatoptions-=t
set textwidth=79

" get rid of the default style of C comments, and define a style with two stars
" at the start of `middle' rows which (looks nicer and) avoids asterisks used
" for bullet lists being treated like C comments; then define a bullet list
" style for single stars (like already is for hyphens):
set comments-=s1:/*,mb:*,ex:*/
set comments+=s:/*,mb:**,ex:*/
set comments+=fb:*

" treat lines starting with a quote mark as comments (for `Vim' files, such as
" this very one!), and colons as well so that reformatting usenet messages from
" `Tin' users works OK:
set comments+=b:\"
set comments+=n::


"** Specific File Formats

if has('autocmd')
   " enable filetype detection:
   filetype on

   " recognize  all with a .txt extension as being human-language text [this clobbers the
   " `help' filetype, but that doesn't seem to prevent help from working
   " properly]:
   augroup filetype
      autocmd BufNewFile,BufRead *.txt set filetype=human
   augroup END

   " in human-language files, automatically format everything at 72 chars:
   autocmd FileType human set formatoptions+=t textwidth=72

   " for C-like programming, have automatic indentation:
   autocmd FileType c,cpp,slang set cindent

   " for actual C (not C++) programming where comments have explicit end
   " characters, if starting a new line in the middle of a comment automatically
   " insert the comment leader characters:
   autocmd FileType c set formatoptions+=ro

   " in makefiles, don't expand tabs to spaces, since actual tab characters are
   " needed, and have indentation at 8 chars to be sure that all indents are tabs
   " (despite the mappings later):
   autocmd FileType make set noexpandtab shiftwidth=8
endif

" APPARENCE "
"""""""""""""

set columns=120
set lines=80

" have syntax highlighting in terminals or gui which can display colours:
if (has('syntax') || has('gui_running')) && (&t_Co > 2)
  syntax on
endif

" Change gui font
set guifont=Lucida_Console:h8:cDEFAULT

" Change to dark background mode
set background=dark

" Use default colorscheme
colorscheme ir_black

" use "[RO]" for "[readonly]" to save space in the message line:
set shortmess+=r

" display the current mode and partially-typed commands in the status line:
set showmode
set showcmd

" show the cursor position all the time
set ruler

" show line numbers
set number

" Highlight search terms
set hlsearch

" Show matching brackets
set showmatch

" Permanent status line
set laststatus=2

"Signal lines larger then 80 characters
highlight rightMargin term=bold ctermfg=red guifg=red guibg=yellow
match rightMargin /\%<82v.\%>81v/

" when using list, keep tabs at their full width and display `arrows':
execute 'set listchars+=tab:' . nr2char(187) . nr2char(183)
" (Character 187 is a right double-chevron, and 183 a mid-dot.)

" KEY MAPPING "
"""""""""""""""

"** Remaps
"
" When yanking something we selected go to the last caracter selected (uses z
" mark
vnoremap y mzy`z

"Singal insert/command mode with line number color
noremap i :highlight LineNr ctermfg=DarkGreen guifg=DarkGreen<cr>i
noremap o :highlight LineNr ctermfg=DarkGreen guifg=DarkGreen<cr>o
noremap s :highlight LineNr ctermfg=DarkGreen guifg=DarkGreen<cr>s
noremap a :highlight LineNr ctermfg=DarkGreen guifg=DarkGreen<cr>a
noremap I :highlight LineNr ctermfg=DarkGreen guifg=DarkGreen<cr>I
noremap O :highlight LineNr ctermfg=DarkGreen guifg=DarkGreen<cr>O
noremap S :highlight LineNr ctermfg=DarkGreen guifg=DarkGreen<cr>S
noremap A :highlight LineNr ctermfg=DarkGreen guifg=DarkGreen<cr>A
inoremap <Esc> <Esc>:highlight LineNr ctermfg=DarkRed guifg=DarkRed<cr>


" COMMANDS "
""""""""""""
" Changes the operants in an assignation 
command! -range SwapOps :s/\([^ =]*\)\s*=\s*\([^;]*\)\s*/\2 = \1


" EXPERIMENTAL "
""""""""""""""""


" PLUGINS "
"""""""""""

"source .vimrc.plugins


""""""""""""""""""
" OTHERS
""""""""""""""""""

" remember all of these between sessions, but only 10 search terms; also
" remember info for 10 files, but never any on removable disks, don't remember
" marks in files, don't rehighlight old search patterns, and only save up to
" 100 lines of registers; including @10 in there should restrict input buffer
" but it causes an error for me:
"set viminfo=/10,'10,r/mnt/zip,r/mnt/floppy,f0,h,\"100
